"""技术指标阈值配置模块.

包含所有技术指标的默认阈值配置，支持自定义阈值。
"""

from __future__ import annotations

import logging
from typing import Any, Dict, Optional

from .types import SignalDirection, SignalResult, SignalStrength

logger = logging.getLogger(__name__)


class IndicatorThresholds:
    """技术指标阈值配置类.
    
    包含所有技术指标的默认阈值配置，支持自定义阈值。
    """
    
    def __init__(self, custom_thresholds: Optional[Dict[str, Any]] = None):
        """初始化阈值配置.
        
        Parameters
        ----------
        custom_thresholds : Optional[Dict[str, Any]], optional
            自定义阈值字典，如果提供则覆盖默认阈值
        """
        # RSI阈值：超卖<30，超买>70
        self.rsi_oversold = 30
        self.rsi_overbought = 70
        
        # CMO阈值：超卖<-50，超买>50
        self.cmo_oversold = -50
        self.cmo_overbought = 50
        
        # KDJ阈值：超卖<20，超买>80
        self.kdj_oversold = 20
        self.kdj_overbought = 80
        
        # Williams %R阈值：超卖<-80，超买>-20
        self.williams_r_oversold = -80
        self.williams_r_overbought = -20
        
        # CCI阈值：超卖<-100，超买>100
        self.cci_oversold = -100
        self.cci_overbought = 100
        
        # MFI阈值：超卖<20，超买>80
        self.mfi_oversold = 20
        self.mfi_overbought = 80
        
        # 布林带阈值：下轨位置<0.2，上轨位置>0.8
        self.bollinger_lower = 0.2
        self.bollinger_upper = 0.8
        
        # 价格百分位阈值：低位<20，高位>80
        self.price_percentile_lower = 20
        self.price_percentile_upper = 80
        
        # VWAP偏差阈值：低位<-0.02，高位>0.02
        self.vwap_bias_lower = -0.02
        self.vwap_bias_upper = 0.02
        
        # OBV比率阈值：低位<0.9，高位>1.1
        self.obv_ratio_lower = 0.9
        self.obv_ratio_upper = 1.1
        
        # ADX趋势强度阈值：强趋势>25
        self.adx_strong_trend = 25
        
        # 趋势持续性阈值：强烈看多>5，强烈看空<-5
        self.trend_persistence_strong_bullish = 5
        self.trend_persistence_strong_bearish = -5
        
        # 如果提供了自定义阈值，则覆盖默认值
        if custom_thresholds:
            for key, value in custom_thresholds.items():
                if hasattr(self, key):
                    setattr(self, key, value)
                else:
                    logger.warning(f"未知的阈值配置项: {key}")

